package com.cy.stone.system.adapter;

import com.cy.stone.common.base.AddGroup;
import com.cy.stone.common.base.EditGroup;
import com.cy.stone.framework.log.annotation.Log;
import com.cy.stone.framework.log.enums.BusinessType;
import com.cy.stone.system.application.DictDataApi;
import com.cy.stone.system.domain.clientobject.dict.DictDataCO;
import com.cy.stone.system.domain.clientobject.dict.DictDataPageCO;
import com.cy.stone.system.domain.dto.dict.DictDataDTO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dictData/")
@RequiredArgsConstructor
@Tag(name = "字典数据服务适配器")
public class DictDataController {

    private final DictDataApi dictDataApi;

    @PostMapping("page")
    @Operation(summary = "分页查询")
    public Page<DictDataDTO> page(@RequestBody @Validated DictDataPageCO dictDataPageCO) {
        return dictDataApi.page(dictDataPageCO);
    }

    @PostMapping("addDictData")
    @Operation(summary = "新增字典数据")
    @Log(title = "新增字典数据", businessType = BusinessType.INSERT, isSaveResponseData = false)
    public void addDictData(@RequestBody @Validated(AddGroup.class) DictDataCO dictDataCO) {
        dictDataApi.addDictData(dictDataCO);
    }

    @PostMapping("editDictData")
    @Operation(summary = "编辑字典数据")
    @Log(title = "编辑字典数据", businessType = BusinessType.UPDATE, isSaveResponseData = false)
    public void editDictData(@RequestBody @Validated(EditGroup.class) DictDataCO dictDataCO) {
        dictDataApi.editDictData(dictDataCO);
    }
}
